CC=gcc
CFLAGS= -Wall -w -g
EXEC = exec
ARCHI= X86_32

EXEC : example.c 
	$(CC) $(CFLAGS) -lthread example.c -o $(EXEC)

uninstall :
	rm -f /usr/lib/libthread.so.1 
	rm -f /usr/include/types.h /usr/include/thread.h /usr/include/list.h /usr/include/element.h /usr/include/semaphores.h /usr/include/spinlock.h 

install : lib_thread.o lib_list.o lib_element.o lib_sem.o 
	$(CC) -shared -o libthread.so.1 -Wl,-soname,libthread.so.1 lib_thread.o lib_list.o lib_element.o lib_sem.o
	cp -v -f libthread.so.1 /usr/lib/
	ln -sfv /usr/lib/libthread.so.1 /usr/lib/libthread.so
	cp -v -f types.h thread.h list.h element.h semaphores.h spinlock.h /usr/include/

lib_thread.o : thread.c
	$(CC) -fPIC -g -c thread.c -o lib_thread.o

lib_list.o:  list.c
	$(CC) -fPIC -g -c list.c -o lib_list.o

lib_element.o:  element.c
	$(CC) -fPIC -g -c element.c -o lib_element.o

lib_sem.o: semaphores.c
	$(CC) -fPIC -c -D $(ARCHI) semaphores.c -o lib_sem.o 

thread.o: thread.c 
	$(CC) $(CFLAGS) -c thread.c 

list.o : list.c 
	$(CC) $(CFLAGS) -c list.c 

element.o : element.c 
	$(CC) $(CFLAGS) -c element.c 

semaphores.o : semaphores.c
	$(CC) $(CFLAGS) -c -D $(ARCHI) semaphores.c

clean :
	rm *.o $(EXEC)
